package com.xie.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xie.domain.Result;
import com.xie.pojo.Appartus;
import com.xie.pojo.Manager;
import com.xie.service.AppartusService;
import com.xie.service.ManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "排班信息管理")
@RestController
@RequestMapping(value = "/Managers")
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    /**
     * 分页查询
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @ApiOperation("获取分页排班数据")
    @GetMapping("{pageIndex}/{pageSize}")
    public Result findAppartus(@PathVariable Integer pageIndex
            , @PathVariable Integer pageSize){
        Page page=new Page(pageIndex,pageSize);
        IPage page1 = managerService.page(page);
        if (page1!= null) return Result.ok(page1);
        return Result.fail();
    }

    /**
     * 添加
     * @param manager
     * @return
     */
    @ApiOperation("添加排班信息")
    @PostMapping("/save")
    public Result addAppartus(@RequestBody Manager manager) {
        boolean save = managerService.save(manager);
        if (!save) {
            return Result.fail();
        }
        return Result.ok();
    }


    /**
     * 修改
     * @param manager
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改排班信息")
    public Result updateAdmin(@RequestBody Manager manager) {
        boolean update = managerService.updateById(manager);
        if (!update) return Result.fail();
        return Result.ok();
    }

    /**
     * 获取全部
     * @return
     */
    @GetMapping("/findlist")
    @ApiOperation("获取全部排班数据")
    public Result exportAdmin(){
        List<Manager> list = managerService.list();
        List list1=new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            Manager manager = list.get(i);
            if ("有班".equals(manager.getOne())){
                list1.add("星期一"+manager.getName());
            }
            if ("有班".equals(manager.getTwo())){
                list1.add("星期二"+manager.getName());
            }
            if ("有班".equals(manager.getThree())){
                list1.add("星期三"+manager.getName());
            }
            if ("有班".equals(manager.getFour())){
                list1.add("星期四"+manager.getName());
            }
            if ("有班".equals(manager.getFive())){
                list1.add("星期五"+manager.getName());
            }
            if ("有班".equals(manager.getSix())){
                list1.add("星期六"+manager.getName());
            }
            if ("有班".equals(manager.getSeven())){
                list1.add("星期日"+manager.getName());
            }

        }
        return Result.ok(list1);
//        if (appartus!= null) return Result.ok(appartus);
//        return Result.fail();
    }


}
